package com.ruoyi.web.controller.resturant;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.resturant.domain.Student;
import com.ruoyi.resturant.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Anonymous
@RestController
@RequestMapping("/api/resturant/student")
@Api(tags = "学生信息管理")
public class StudentsController {

    @Autowired
    private IStudentService studentService;

    @ApiOperation("获取所有的学生列表")
    @GetMapping("/list")
    private AjaxResult getStuents() {

        List<Student> rs =  studentService.getStudents();

        return AjaxResult.success(rs);
    }

    @ApiOperation("根据id查询学生信息")
    @GetMapping("/selectById")
    private AjaxResult selectStudentById(Long id) {
        Student rs =  studentService.selectStudentById(id);
        return AjaxResult.success(rs);
    }

    /**
     * 获取学生详细信息
     */
    @ApiOperation(value = "获取学生详细信息", notes = "TODO：取得某个学生的详细信息")
    @ApiImplicitParam(name = "id", value = "学生ID",
            required = true, dataType = "long", paramType = "path",
            dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        Student student = studentService.selectStudentById(id);
        return AjaxResult.success(student);
    }

    /**
     * 新增店铺
     */
    @ApiOperation("新增学生")
    @PostMapping
    public AjaxResult add(@RequestBody Student student) {
        return AjaxResult.success(studentService.insertStudent(student));
    }


    /**
     * 修改学生
     */
    @ApiOperation("修改学生")
    @PutMapping
    public AjaxResult edit(@RequestBody Student student) {
        return AjaxResult.success(studentService.updateStudent(student));
    }

    /**
     * 删除学生
     */
    @ApiOperation("删除学生")
    @ApiImplicitParam(name = "id", value = "学生ID", required = true, dataType = "long",
            paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return AjaxResult.success(studentService.deleteStudentById(id));
    }
}

